import { parseTime, byKeyGetItem } from '@/utils'
import { partsStatusMap, roleTypeMap, judgeTypeMap } from '@/config/dict'
import { CustomStatus } from '@/components'

export const tableColumn = (handleEdit, handleRole, handleDataAuth, handleDelete) => {
  return [
    {
      key: 'name',
      label: '角色名称',
      minWidth: 140
    },
    {
      key: 'isAdmin',
      label: '是否默认',
      minWidth: 140,
      render: (h, scope) => <CustomStatus list={judgeTypeMap} value={scope.row.isAdmin} />
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 100,
      render: (h, scope) => <CustomStatus list={partsStatusMap} value={scope.row.status} subKey='subKey' />
    },
    {
      key: 'roleType',
      label: '角色类别',
      minWidth: 120,
      render: (h, scope) => byKeyGetItem(roleTypeMap, scope.row.roleType).value
    },
    {
      key: 'updateName',
      label: '最后修改人',
      minWidth: 140
    },
    {
      key: 'updateTime',
      label: '最后修改时间',
      minWidth: 200,
      render: (h, scope) => parseTime(scope.row.updateTime)
    },
    {
      type: 'button',
      label: '操作',
      minWidth: 240,
      list: [
        {
          name: '修改',
          authKey: 'e_1_2',
          isDisabled: (scope) => scope.row.isAdmin,
          click: handleEdit
        },
        {
          name: '操作权限',
          authKey: 'e_1_4',
          click: handleRole
        },
        {
          name: '数据权限',
          authKey: 'e_1_5',
          click: handleDataAuth
        },
        {
          name: '删除',
          authKey: 'e_1_3',
          confirm: '是否删除?',
          disabled: true,
          isDisabled: (scope) => scope.row.isAdmin,
          click: handleDelete
        }
      ]
    }
  ]
}

export const modalFormItem = (list) => {
  return [
    {
      type: 'select',
      label: '机构',
      required: true,
      key: 'orgId',
      slotAttrs: {
        options: list,
        disabled: true
      }
    },
    {
      type: 'select',
      label: '角色类别',
      required: true,
      key: 'roleType',
      slotAttrs: {
        options: roleTypeMap
      }
    },
    {
      type: 'input',
      label: '角色名称',
      required: true,
      key: 'name'
    },
    {
      type: 'radio',
      label: '状态',
      key: 'status',
      required: true,
      slotAttrs: {
        options: partsStatusMap,
        optionKey: { key: 'subKey', value: 'value' }
      }
    },
    {
      type: 'input',
      label: '备注',
      key: 'remark'
    }
  ]
}

export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}
